<template>
    <div>
        <el-dialog top="5%" :title="title" size="large" v-model="editFormVisible" :close-on-click-modal="false">
            <el-form  ref="form" :model="form" :inline="true" :rules="rules" label-width="150px">
            <el-form-item label="工程">
                <el-input disabled  v-model="form.FName" style="width:250px;"></el-input>
            </el-form-item>
        </el-form>
            <div style="border: 1px solid #bbb; padding: 20px;">

            <el-table
                    :data="listdata"
                    border
                    v-loading="listLoading"
                    style="width: 100%">
                <el-table-column
                        prop="FSubitemName"
                        label="单项工程"
                        width="280">
                </el-table-column>
                <el-table-column
                        v-for="(item,index) in columnslist"
                        :prop="'FItem'+(index+1)"
                        :label="item.FName"
                        width="120">
                    <template scope="scope">
                        <el-input type="number"  v-model.number="scope.row['FItem'+(index+1)]"></el-input>
                    </template>
                </el-table-column>
            </el-table>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="editFormVisible = false">取 消</el-button>
                <el-button type="primary" v-if="showSave" @click="save" :loading="loading">保存</el-button>
            </div>
      </el-dialog>
    </div>
</template>

<script>
    import util from '../../common/util'
    import mixin from '../../common/mixin'
    import Vue from 'vue'
    export default {
        data() {
            return {
                form: {},
                showSave:true,
                rules: {
                   // FName: [{type: "date",name:"FCreateDate",text:"跟进时间", value: null}]
                },
                loading:false,
                editFormVisible:false,
                title:'',
                listdata: [],
                listLoading:false,
                showcontent:true,
                fixWhere:'',
                columnslist:[]
            }
        },
        computed: {

        },
        methods: {
            switchLoading(flag){
                this.loading = flag;
            },
            _openEdit(record) {
                this.editFormVisible = true;
                this.form = Object.assign({},record);
                this.title = '编辑'
                util.get("server/business/Single.ashx?cmd=GetList",
                    {where:"FProjectID="+this.form.FID,start:"0",limit:'10'},this.switchLoading,result=>{
                        this.columnslist = result.data
                    })
                util.get("server/business/ScheduleTarget.ashx?cmd=GetList",
                    {where:"FProjectID="+this.form.FID},this.switchLoading,result=>{
                       if(result.listdata.length!=0) {
                        this.listdata = result.listdata
                       }
                       else{
                           util.get("server/business/Subitem.ashx?cmd=GetList",
                               {where:"FProjectID="+this.form.FID,start:"0",limit:'100'},this.switchLoading,result=>{
                                  for(let pro of result.data)
                                  {
                                      this.listdata.push({FSubitemID:pro.FID,FItem1:'',FItem2:'',FItem3:'',FItem4:'',FItem5:'',
                                      FItem6:'',FItem7:'',FItem8:'',FItem9:'',FItem10:'',FProjectID:this.form.FID,FSubitemName:pro.FName})
                                  }
                               })
                       }
                    })
            },
            save:function () {
                this.form.listdata = JSON.stringify(this.listdata);
                util.post("server/business/ScheduleTarget.ashx?cmd=Save",this.form,this.switchLoading,result=> {
                    util.msgSuc("保存成功")
                    this.editFormVisible = false
                    this.$emit("onSaveSuc", this.form)

                })
            }
        },
        mounted() {

        }
    }
</script>
